package design_patterns;

/**
 * 单例模式（双重校验锁）
 *
 * @author yujiafan
 * @version 1.0.0
 * @create 2023-07-24
 */
public class SingletonDCL {
    private static volatile SingletonDCL singletonDCL;

    private SingletonDCL() {

    }

    public static SingletonDCL getInstance() {
        if(singletonDCL == null) {
            synchronized (SingletonDCL.class) {
                if(singletonDCL == null) {
                    singletonDCL = new SingletonDCL();
                }
            }
        }
        return singletonDCL;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(getInstance().hashCode())).start();
        }
    }
}
